package com.googlecode.mailnet.emf.netmodel.ui;

import org.eclipse.gef.EditPart;
import org.eclipse.jface.viewers.IFilter;

import com.googlecode.mailnet.emf.netmodel.LinkModel;
import com.googlecode.mailnet.emf.netmodel.NetworkConfigurationModel;
import com.googlecode.mailnet.emf.netmodel.diagram.edit.parts.LinkModelEditPart;
import com.googlecode.mailnet.emf.netmodel.diagram.edit.parts.LinkModelNameEditPart;
import com.googlecode.mailnet.emf.netmodel.diagram.edit.parts.NetworkConfigurationModelEditPart;
import com.googlecode.mailnet.emf.netmodel.diagram.edit.parts.NodeModelEditPart;

public class InfoPropertySectionFilter implements IFilter {

	@Override
	public boolean select(Object toTest) {
		if (toTest instanceof LinkModelNameEditPart) {
			LinkModelNameEditPart ep = (LinkModelNameEditPart) toTest;
			return ep.resolveSemanticElement() instanceof LinkModel;
		} else if (toTest instanceof NodeModelEditPart || toTest instanceof LinkModelEditPart) {
			if (((EditPart) toTest).getParent() instanceof NetworkConfigurationModelEditPart) {
				NetworkConfigurationModelEditPart editPart = (NetworkConfigurationModelEditPart) ((EditPart) toTest).getParent();
				return ((NetworkConfigurationModel) editPart.resolveSemanticElement()).getSimulationContext() != null;
			}
			return true;
		} else if (toTest instanceof NetworkConfigurationModelEditPart) {
			NetworkConfigurationModelEditPart editPart = (NetworkConfigurationModelEditPart) toTest;
			return ((NetworkConfigurationModel) editPart.resolveSemanticElement()).getSimulationContext() != null;
		} else return false;
	}

}
